package com.zgjkhis.modules.system.rest;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zgjkhis.modules.system.domain.Region;
import com.zgjkhis.modules.system.domain.vo.RegionTree;
import com.zgjkhis.modules.system.domain.vo.RegionVO;
import com.zgjkhis.modules.system.service.RegionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;

/**
 * 行政区划表 控制器
 *
 */


@Api(tags = "行政区划表：行政区划表管理")
@RestController
@RequestMapping("/api/region")
public class RegionController {

	private final RegionService regionService;

	public RegionController(RegionService regionService) {
		this.regionService = regionService;
	}

//	/**
//	 * 详情
//	 */
//	@GetMapping("/detail")
//	@ApiOperationSupport(order = 1)
//	@ApiOperation(value = "详情", notes = "传入region")
//	public R<RegionVO> detail(Region region) {
//		Region detail = regionService.getOne(Condition.getQueryWrapper(region));
//		return R.data(RegionWrapper.build().entityVO(detail));
//	}
//
//	/**
//	 * 分页 行政区划表
//	 */
//	@GetMapping("/list")
//	@ApiOperationSupport(order = 2)
//	@ApiOperation(value = "分页", notes = "传入region")
//	public R<IPage<Region>> list(Region region, Query query) {
//		IPage<Region> pages = regionService.page(Condition.getPage(query), Condition.getQueryWrapper(region));
//		return R.data(pages);
//	}

	/**
	 * 懒加载列表
	 */
	@GetMapping("/lazy-list")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "code", value = "区划编号", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "name", value = "区划名称", paramType = "query", dataType = "string")
	})
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "懒加载列表", notes = "传入menu")
	public ResponseEntity<List<RegionVO>> lazyList(String parentCode, @ApiIgnore @RequestParam Map<String, Object> menu) {
		List<RegionVO> list = regionService.lazyList(parentCode, menu);
		return new ResponseEntity<>(list, HttpStatus.OK);
	}

	/**
	 * 懒加载列表
	 */
	@GetMapping("/lazy-tree")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "code", value = "区划编号", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "name", value = "区划名称", paramType = "query", dataType = "string")
	})
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "懒加载列表", notes = "传入menu")
	public ResponseEntity<List<RegionTree>> lazyTree(String parentCode, @ApiIgnore @RequestParam Map<String, Object> menu) {
		List<RegionTree> list = regionService.lazyTree(parentCode, menu);
		return new ResponseEntity<>(list, HttpStatus.OK);
	}

//	/**
//	 * 新增 行政区划表
//	 */
//	@PostMapping("/save")
//	@ApiOperationSupport(order = 5)
//	@ApiOperation(value = "新增", notes = "传入region")
//	public R save(@Valid @RequestBody Region region) {
//		return R.status(regionService.save(region));
//	}

	/**
	 * 行政区划下拉数据源
	 */
	@GetMapping("/select")
	@ApiOperationSupport(order = 9)
	@ApiOperation(value = "下拉数据源", notes = "传入tenant")
	public ResponseEntity<Object> select(@RequestParam(required = false, defaultValue = "00") String code) {
		List<Region> list = regionService.list(Wrappers.<Region>query().lambda().eq(Region::getParentCode, code));
		return new ResponseEntity<>(list, HttpStatus.OK);
	}



}
